﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Fluent="clr-namespace:Fluent"
                    xmlns:Internal="clr-namespace:Fluent.Internal"
                    xmlns:Converters="clr-namespace:Fluent.Converters">          
    <ControlTemplate x:Key="BackstageButtonControlTemplate"
                     TargetType="{x:Type Fluent:Button}">
        <Grid Background="#00000000">
            <Border x:Name="border"
                    Visibility="Collapsed">
                <Border.Background>
                    <SolidColorBrush Opacity="0.2"
                                     Color="Black" />
                </Border.Background>
            </Border>
            <StackPanel Orientation="Horizontal"
                        Margin="25,0,15,0"
                        HorizontalAlignment="Left"
                        VerticalAlignment="Center">
                <TextBlock Text="{TemplateBinding Header}"
                           TextWrapping="NoWrap"
                           VerticalAlignment="Center"
                           HorizontalAlignment="Left"
                           TextTrimming="CharacterEllipsis"
                           x:Name="controlLabel" />
            </StackPanel>
        </Grid>
        <ControlTemplate.Triggers>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsMouseOver"
                               Value="True" />
                    <Condition Property="IsEnabled"
                               Value="True" />
                </MultiTrigger.Conditions>
                <Setter Property="Visibility"
                        TargetName="border"
                        Value="Visible" />
            </MultiTrigger>
            <Trigger Property="IsEnabled"
                     Value="False">
                <Setter Property="Opacity"
                        TargetName="controlLabel"
                        Value="0.5" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
    
    <Style x:Key="BackstageButtonStyle"
           TargetType="{x:Type Fluent:Button}">
        <Setter Property="FocusVisualStyle"
                Value="{DynamicResource ControlStyleEmptyFocus}" />
        <Setter Property="Height"
                Value="38" />
        <Setter Property="Margin"
                Value="0" />
        <Setter Property="Template"
                Value="{DynamicResource BackstageButtonControlTemplate}" />
        <Setter Property="Background"
                Value="{Binding Background, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Fluent:BackstageTabControl}}, FallbackValue=Red}" />
        <Setter Property="Foreground"
                Value="{DynamicResource BackstageFontBrush}" />
    </Style>

    <ControlTemplate x:Key="BackstageBackButtonTemplate" TargetType="Button">
        <Grid x:Name="ContentGrid"
              Fluent:FrameworkHelper.UseLayoutRounding="False">
            <Path x:Name="arrowpath"
                  Width="16"
                  Height="12"
                  Canvas.Top="10"
                  Canvas.Left="7.5"
                  Stretch="Uniform"
                  Fill="White"
                  Data="F1 M 36,22L 36,26L 19.75,26L 27,33L 20.5,33L 11,24L 20.5,15L 27,15L 19.75,22L 36,22 Z " />

            <Ellipse x:Name="backellipse"
                     Stroke="White"
                     Height="35"
                     Canvas.Left="0"
                     Width="35"
                     StrokeThickness="2" />

            <Path Data="M0,0 C0,35 0,35 0,35 C0,35 35,35 35,35 L35,0 z"
                  Fill="Transparent"
                  HorizontalAlignment="Stretch"
                  Margin="0"
                  Stretch="None"
                  Width="Auto" />
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver"
                     Value="True">
                <Setter Property="Opacity"
                        TargetName="arrowpath"
                        Value="0.5" />
                <Setter Property="Opacity"
                        TargetName="backellipse"
                        Value="0.5" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>
    
    <Style x:Key="BackstageBackButtonStyle" TargetType="{x:Type Button}">
        <Setter Property="Height" Value="35" />
        <Setter Property="Width" Value="35" />
        <Setter Property="Template" Value="{DynamicResource BackstageBackButtonTemplate}" />
    </Style>


    <Style TargetType="{x:Type Fluent:SeparatorTabItem}"
           x:Key="BackstageSeparatorTabItemStyle">
        <Setter Property="Margin" Value="25,10,20,10"></Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Fluent:SeparatorTabItem}">
                    <StackPanel>
                        <TextBlock x:Name="header"
                                   Margin="10,5"
                                   TextWrapping="Wrap"
                                   Text="{TemplateBinding Header}"
                                   VerticalAlignment="Center"
                                   FontSize="14"
                                   FontWeight="SemiBold"
                                   Foreground="{DynamicResource BackstageFontBrush}"
                                   Visibility="Visible" />
                        <Line MinWidth="75" Height="1" X2="1" Stroke="#17FFFFFF" Stretch="Uniform" />
                    </StackPanel>
                    <ControlTemplate.Triggers>
                        <Trigger Property="HasHeader"
                                 Value="False">
                            <Setter TargetName="header"
                                    Property="Visibility"
                                    Value="Collapsed" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <ControlTemplate x:Key="BackstageControlTemplate"
                     TargetType="{x:Type Fluent:BackstageTabControl}">
        <ControlTemplate.Resources>
            <ResourceDictionary>
                <Style x:Key="{x:Type Fluent:Button}"
                       TargetType="{x:Type Fluent:Button}"
                       BasedOn="{StaticResource BackstageButtonStyle}" />
                <Style x:Key="{x:Type ScrollBar}"
                       TargetType="{x:Type ScrollBar}"
                       BasedOn="{StaticResource ScrollBarWhite}" />
                <Style x:Key="{x:Type Fluent:DropDownButton}"
                       TargetType="{x:Type Fluent:DropDownButton}"
                       BasedOn="{StaticResource DropDownButtonBackstageStyle}" />
                <Style x:Key="{x:Type Fluent:ComboBox}"
                       TargetType="{x:Type Fluent:ComboBox}"
                       BasedOn="{StaticResource ComboBoxBackstageStyle}" />
                <Style x:Key="{x:Type Fluent:Spinner}"
                       TargetType="{x:Type Fluent:Spinner}"
                       BasedOn="{StaticResource SpinnerBackstageStyle}" />
                <Style TargetType="{x:Type Fluent:SeparatorTabItem}"
                       BasedOn="{StaticResource BackstageSeparatorTabItemStyle}" />
                <Storyboard x:Key="OnIsOpenTrueStoryboard">
                    <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)"
                                                      Storyboard.TargetName="grid">
                        <Fluent:EasingThicknessKeyFrame KeyTime="0"
                                                        Value="-30,0,0,0" />
                        <Fluent:EasingThicknessKeyFrame KeyTime="0:0:0.2"
                                                        Value="0">
                            <Fluent:EasingThicknessKeyFrame.EasingFunction>
                                <Fluent:CubicEase EasingMode="EaseInOut" />
                            </Fluent:EasingThicknessKeyFrame.EasingFunction>
                        </Fluent:EasingThicknessKeyFrame>
                    </ThicknessAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)"
                                                   Storyboard.TargetName="grid">
                        <Fluent:EasingDoubleKeyFrame KeyTime="0"
                                                     Value="0" />
                        <Fluent:EasingDoubleKeyFrame KeyTime="0:0:0.2"
                                                     Value="1" />
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>
                <Storyboard x:Key="OnIsOpenFalseStoryboard">
                    <ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)"
                                                      Storyboard.TargetName="grid">
                        <Fluent:EasingThicknessKeyFrame KeyTime="0"
                                                        Value="0" />
                        <Fluent:EasingThicknessKeyFrame KeyTime="0:0:0.2"
                                                        Value="-30,0,0,0">
                            <Fluent:EasingThicknessKeyFrame.EasingFunction>
                                <Fluent:CubicEase EasingMode="EaseInOut" />
                            </Fluent:EasingThicknessKeyFrame.EasingFunction>
                        </Fluent:EasingThicknessKeyFrame>
                    </ThicknessAnimationUsingKeyFrames>
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)"
                                                   Storyboard.TargetName="grid">
                        <Fluent:EasingDoubleKeyFrame KeyTime="0"
                                                     Value="1" />
                        <Fluent:EasingDoubleKeyFrame KeyTime="0:0:0.2"
                                                     Value="0" />
                    </DoubleAnimationUsingKeyFrames>
                </Storyboard>                
            </ResourceDictionary>
        </ControlTemplate.Resources>
        <Grid x:Name="grid"
              Margin="0"
              Background="{DynamicResource BackstageBackgroundBrush}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition MinWidth="115"
                                  Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Grid Height="Auto"
                  Grid.Column="1">
                <Grid.Resources>
                    <ResourceDictionary>
                        <Style x:Key="{x:Type Fluent:Button}"
                               TargetType="{x:Type Fluent:Button}"
                               BasedOn="{StaticResource BackstageButtonStyle}" />
                    </ResourceDictionary>
                </Grid.Resources>
                <ContentPresenter x:Name="PART_SelectedContentHost"
                                  HorizontalAlignment="Stretch"
                                  VerticalAlignment="Stretch"
                                  Height="Auto"
                                  Grid.Column="1"
                                  ContentSource="SelectedContent" />
            </Grid>
            <Grid VerticalAlignment="Stretch"
                  Background="{DynamicResource RibbonThemeColorBrush}">
                <Grid.Margin>
                    <MultiBinding Converter="{x:Static Converters:StaticConverters.ThicknessConverter}">
                        <Binding Source="{x:Static Internal:DoubleUtil.Zero}" />
                        <Binding RelativeSource="{RelativeSource Self}"
                                 Path="(Fluent:RibbonProperties.TitleBarHeight)"
                                 Converter="{x:Static Converters:StaticConverters.InvertNumericConverter}" />                        
                        <Binding Source="{x:Static Internal:DoubleUtil.Zero}" />
                        <Binding Source="{x:Static Internal:DoubleUtil.Zero}" />
                    </MultiBinding>
                </Grid.Margin>
                <Button x:Name="backbutton"
                        Style="{DynamicResource BackstageBackButtonStyle}"
                        Command="{x:Static Fluent:RibbonCommands.OpenBackstage}"
                        Width="35"
                      Height="35"
                      Margin="22,19,0,0"
                      VerticalAlignment="Top"
                        HorizontalAlignment="Left">
                </Button>
                
                <ItemsPresenter Margin="0,69,0,0"
                                Height="Auto" />
            </Grid>
        </Grid>
        <ControlTemplate.Triggers>
            <DataTrigger Binding="{Binding IsOpen, RelativeSource={RelativeSource AncestorType={x:Type Fluent:Backstage}}}"
                         Value="True">
                <DataTrigger.EnterActions>
                    <RemoveStoryboard BeginStoryboardName="IsClosedBeginStoryboard" />
                    <BeginStoryboard x:Name="IsOpenBeginStoryboard" Storyboard="{StaticResource OnIsOpenTrueStoryboard}" />
                </DataTrigger.EnterActions>
                <DataTrigger.ExitActions>
                    <BeginStoryboard x:Name="IsClosedBeginStoryboard"
                                     Storyboard="{StaticResource OnIsOpenFalseStoryboard}" />
                    <RemoveStoryboard BeginStoryboardName="IsOpenBeginStoryboard" />
                </DataTrigger.ExitActions>
            </DataTrigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style x:Key="BackstageStyle"
           TargetType="{x:Type Fluent:BackstageTabControl}">
        <Setter Property="Foreground"
                Value="{DynamicResource DefaultFontBrush}" />
        <Setter Property="Template"
                Value="{DynamicResource BackstageControlTemplate}" />
        <Setter Property="FocusVisualStyle"
                Value="{DynamicResource ControlStyleEmptyFocus}" />
        <Setter Property="Margin"
                Value="0,-24,0,1" />
        <Setter Property="Background"
                Value="{Binding Background, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Fluent:Backstage}}, FallbackValue=Red}" />
        <Setter Property="ItemsPanelBackground"
                Value="{DynamicResource BackstagePanelBackgroundBrush}" />
    </Style>
</ResourceDictionary>